package com.amqp.demo;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;

public class ReceiveMsgHandler2 implements ChannelAwareMessageListener {
    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        //message.getMessageProperties().getReceivedRoutingKey()
        String receivedRoutingKey = message.getMessageProperties().getReceivedRoutingKey();
        System.out.println("Received: " + new String(message.getBody()));
        //System.out.println(receivedRoutingKey);
        channel.basicReject(message.getMessageProperties().getDeliveryTag(),false);
    }

    /**
     * 需要实现MessageListener
     * @param message
     */
//    @Override
//    public void onMessage(Message message) {
//        //message.getMessageProperties().getReceivedRoutingKey()
//        String receivedRoutingKey = message.getMessageProperties().getReceivedRoutingKey();
//        System.out.println("Received: " + new String(message.getBody()));
//        //System.out.println(receivedRoutingKey);
//    }


//    public void handleMessage(Object ss) throws InterruptedException {
//        System.out.println("Received: " + ss);
//        //Thread.sleep(1000*30);
//        throw new RuntimeException("cc fail");// 消费失败
//    }
}
